package com.fr.lintcode;

import java.util.HashMap;
import java.util.Map;

public class Q1673 {

    /**
     * @param op: the type of information
     * @param name: the name of user
     * @param w: the money need to save or take
     * @return: output the remaining money of the user.if the operation is illegal,output -1
     */
    public int[] getAns(int[] op, String[] name, int[] w) {
        // Write your code here
    	Map<String, Integer> map = new HashMap<>();
    	if(op == null || name == null || w == null) {
    		return new int[0];
    	}
    	int length = op.length;
    	int [] rs = new int[length];
    	for(int i = 0; i < length; i ++) {
    		Integer money = map.get(name[i]);
    		if(op[i] == 0) {
    			if(money == null) {
    				money = 0;
    			}
    			money = money + w[i];
    			map.put(name[i], money);
    			rs[i] = money;
    		}else if(op[i] == 1) {
    			if(money == null || money < w[i]) {
    				rs[i] = -1;
    			}else {
    				money = money - w[i];
    				map.put(name[i], money);
        			rs[i] = money;
    			}
    		}
    	}
    	return rs;
    }


}
